// 导入数据库操作模块
const db = require('../db/index')
const https = require('https');

//  登录接口处理函数
exports.login = (req,res) => {+
    // console.log(req.body.code);
    https.get('https://api.weixin.qq.com/sns/jscode2session?code='+req.body.code, res => {
        res.setEncoding('utf8');
        let rawData = '';
        res.on('data', chunk => { rawData += chunk; });
        res.on('end', () => {
            try {
                const parsedData = JSON.parse(rawData);
                console.log(parsedData);
            } catch (e) {
                console.error(e.message);
            }
        });
    }).on('error', err => {
        console.log('Error: ', err.message);
    });
}

